Assignemnt #49 and Forty-sixth Program
Code
///Name: Derrick Andreasen
///Period: 7
///Program name: forty-sixth Program
///File name: Fourt6Prog.java
///Date Finished:10/22/2015
import java.util.Scanner;
public class Fort6Prog
{
public static void main( String[] args )
{
Scanner keyboard = new Scanner(System.in);
String fName, lName, answer, gender;
int age;
System.out.print( "What is your gender (M or F): " );
gender = keyboard.next();
System.out.print( "First name: " );
fName = keyboard.next();
System.out.print( "Last name: " );
lName = keyboard.next();
System.out.print( "Age: " );
age = keyboard.nextInt();
System.out.println( "" );
if(gender.equals("f"))
{
System.out.print( "Are you married, " + fName + "(Y or N)? " );
answer = keyboard.next();
if(age >= 20)
{
if(answer.equals("y"))
{
System.out.println( "Then I shall call you Mrs. " + lName + ". " );
}
else if(answer.equals("n"))
{
System.out.println( "Then I shall call you Ms. " +lName + ". " );
}
}
else if(age < 20)
{
System.out.println( "Then I shall call you " + fName + " " + lName + ". " );
}
}
if(gender.equals("m"))
{
if(age >= 20)
{
System.out.println( "Then I shall call you Mr. " + lName + ". " );
}
else if(age < 20)
{
System.out.println( "Then I shall call you " + fName + " " + lName + ". " );
}
}
}
}
Picture of the output